import 'dart:async';

import '../util/log_util.dart';

class RunningLogManager{

  RunningLogManager._();

  static final RunningLogManager _instance = RunningLogManager._();
  static RunningLogManager get instance => _instance;

  final StreamController<List<String>> _controller = StreamController.broadcast();

  Stream<List<String>> get runningLogs => _controller.stream.asBroadcastStream();

  StreamSink<List<String>> get _sink => _controller.sink;

  List<String> _logs = ['${DateTime.now()} 运行日志：'];

  void addLog(String log){
    Log.d(log);
    _logs.add('${DateTime.now()} $log');
    _sink.add(_logs);
  }

  List<String> getLogs(){
    return _logs;
  }

  void close(){
    _controller.close();
  }
}